package pe.edu.upc.xcode.pago.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import pe.edu.upc.xcode.pago.domain.Pago;
import pe.edu.upc.xcode.pago.ws.PagoWS;
import pe.edu.upc.xcode.pago.ws.PagoWSImpl;

/**
 * 
 * @author MADELEY
 * @since 23.01.12
 *
 */

@Controller
public class PagoController {

	@Autowired
	PagoWS pagoClient;
	
	@RequestMapping("/pago/ingresar.htm")
	public ModelAndView ingresarPago(HttpServletRequest request,
		HttpServletResponse response) throws Exception {
		String message = "Pago Consulta";
		return new ModelAndView("pago/PagoConsulta", "message", message);
	}
	
	@RequestMapping("/pago/pagoConsulta.htm")
	public ModelAndView pagar(HttpServletRequest request,
		HttpServletResponse response) throws Exception {
		String message =  "Pago Cliente";
		
		String nom1 = request.getParameter("txtNombre_Int1");
		String nom2 = request.getParameter("txtNombre_Int1");
		String ape1 = request.getParameter("txtNombre_Int1");
		String ape2 = request.getParameter("txtNombre_Int1");
		String email = request.getParameter("txtEmail");
		String tarjeta = request.getParameter("txtTarjeta");
				
		Pago beanPago = new Pago();
		
		beanPago.setStrPrimerNombre(nom1);
		beanPago.setStrSegundoNombre(nom2);
		beanPago.setStrApellidoMaterno(ape1);
		beanPago.setStrApellidoMaterno(ape2);
		beanPago.setStrEmail(email);
		beanPago.setStrNroTarjetaCredito(tarjeta);
		
		String rpta = pagoClient.pagar(beanPago);
		
		System.out.println("Result :"+ rpta);
		response.sendRedirect("http://localhost:8080/EvaluacionCrediticia/");
		return null;
	}
	
}
